package net.tv90.bfmccoreqqbot;

import net.tv90.bfmccoreqqbot.command.ClientCommand;
import net.tv90.bfmccoreqqbot.task.MainTask;
import net.tv90.bfmccoreqqbot.util.CommandRegistrar;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

public final class Main extends JavaPlugin {

    public static JavaPlugin plugin;

    private void connect() {
        try {
            new ApplicationContext();
            Bukkit.getScheduler().runTaskTimerAsynchronously(this, new MainTask(), 0L, 0L);
            CommandRegistrar.registerCommand("client", new ClientCommand());
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "client connect");
            Bukkit.getConsoleSender().sendMessage("§eWebSocket已经连接");
        } catch (Exception e) {
            Bukkit.getConsoleSender().sendMessage("§eWebSocket未正常连接");
            e.printStackTrace();
        }
    }

    @Override
    public void onEnable() {
        plugin = this;
        Bukkit.getConsoleSender().sendMessage("§e=========================================================");
        Bukkit.getConsoleSender().sendMessage("§eBFMC QQ机器人功能已经启用");
        Bukkit.getConsoleSender().sendMessage("§e=========================================================");
        connect();
    }

    @Override
    public void onDisable() {
        Bukkit.getConsoleSender().sendMessage("§e=========================================================");
        Bukkit.getConsoleSender().sendMessage("§eBFMC QQ机器人功能已停用");
        Bukkit.getConsoleSender().sendMessage("§e=========================================================");
    }
}
